import wx
import os

import sys
sys.path.append('../')
from Netlist2LOC import *

class MyFrame(wx.Frame):    #创建自定义Frame
    def __init__(self,parent):
        #def __init__(
        # self, parent=None, id=None, title=None, pos=None,
        # size=None, style=None, name=None)
        self.nlproc=Netlist2LOC()
        wx.Frame.__init__(self,parent,id=-1,title="Hello World",size=(600,600)) #设置窗体
        self.CreateStatusBar()
        panel = wx.Panel(self)
        sizer = wx.BoxSizer(wx.VERTICAL)


        panel.SetSizer(sizer)

        txt = wx.StaticText(panel,-1,"Hello World!")    #创建静态文本组件
        txt2 = wx.StaticText(panel,-1,"Hello World!2")    #创建静态文本组件
        btn = wx.Button(panel,-1,u"文件夹选择对话框")
        sizer.Add(txt,0,wx.TOP|wx.LEFT,100)
        sizer.Add(txt2,0,wx.TOP|wx.LEFT,50)
        sizer.Add(btn,0,wx.TOP|wx.LEFT,50)
        
        self.Bind(wx.EVT_BUTTON, self.OnButton, btn)

        self.Center()   #将窗口放在桌面环境的中间
    def OnButton(self, event):
        """"""
        filesFilter = "Dicom (*.csv)|*.csv|" "All File (*.*) | *.*"
        dlg = wx.FileDialog(self, message ="选择单个文件", wildcard = filesFilter, style = wx.FD_OPEN)
        if dlg.ShowModal() == wx.ID_OK:
            print(dlg.GetPath())  #文件夹路径
            self.nlproc.inputFilePath = dlg.GetPath()
            self.nlproc.genSignalLOCMap()
            


        dlg.Destroy()


class MyApp(wx.App):
    def OnInit(self):
        print("开始进入事件循环")
        self.frame = MyFrame(None)
        self.frame.Show(True)
        return True #需要返回一个布尔型，只有初始返回成功，程序才会继续执行

    def OnExit(self):
        print("事件循环结束")
        import time
        time.sleep(2)
        return 0    #返回状态码



def main():
    app = MyApp()

    app.MainLoop()

if __name__ == "__main__":
    main()


